﻿using System;
using System.Collections;
using UnityEngine;

// Token: 0x02000292 RID: 658
public class MicroSpawner : MonoBehaviour
{
	// Token: 0x06000E93 RID: 3731 RVA: 0x000705DA File Offset: 0x0006E7DA
	private void Start()
	{
		this.micros = new MicroNPC[this.maxMicros];
		base.StartCoroutine(this.Routine());
	}

	// Token: 0x06000E94 RID: 3732 RVA: 0x000705FC File Offset: 0x0006E7FC
	private IEnumerator Routine()
	{
		while (ClientPlayer.Instance == null)
		{
			yield return new WaitForSeconds(this.timeInterval);
		}
		for (;;)
		{
			if (this.microCount < this.maxMicros)
			{
				this.SpawnMicro(this.microCount);
				this.microCount++;
			}
			else
			{
				this.CheckIfDead();
			}
			yield return new WaitForSeconds(this.timeInterval);
		}
		yield break;
	}

	// Token: 0x06000E95 RID: 3733 RVA: 0x00070618 File Offset: 0x0006E818
	private void CheckIfDead()
	{
		for (int i = 0; i < this.maxMicros; i++)
		{
			MicroNPC microNPC = this.micros[i];
			if (microNPC == null || microNPC.isDead)
			{
				this.SpawnMicro(i);
				return;
			}
		}
	}

	// Token: 0x06000E96 RID: 3734 RVA: 0x00070664 File Offset: 0x0006E864
	private void SpawnMicro(int i)
	{
		bool flag = UnityEngine.Random.Range(0, 2) == 1;
		MicroNPC tinyAi;
		if (flag)
		{
			tinyAi = NPCSpawner.Instance.SpawnFemaleNPC();
		}
		else
		{
			tinyAi = NPCSpawner.Instance.SpawnMaleNPC();
		}
		GameObject gameObject = ObjectManager.Instance.InstantiateMicro(tinyAi, base.transform.position, base.transform.rotation, base.transform.lossyScale.y);
		this.micros[i] = gameObject.GetComponent<MicroNPC>();
	}

	// Token: 0x040013AB RID: 5035
	private int maxMicros = 20;

	// Token: 0x040013AC RID: 5036
	private int microCount;

	// Token: 0x040013AD RID: 5037
	private float timeInterval = 1f;

	// Token: 0x040013AE RID: 5038
	private MicroNPC[] micros;
}
